package com.example.controller;

import com.example.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/print/abc")
public class PrintABCController {

    @Autowired
    private ReentrantLockPrintABCService reentrantLockPrintABCService;
    @Autowired
    private BlockingQueuePrintABCService blockingQueuePrintABCService;
    @Autowired
    private SemaphorePrintABCService semaphorePrintABCService;
    @Autowired
    private SpinLockPrintABCService spinLockPrintABCService;
    @Autowired
    private LockSupportPrintABCService lockSupportPrintABCService;
    @Autowired
    private WaitNotifyPrintABCService waitNotifyPrintABCService;

    /**
     * 使用 ReentrantLock 打印 AAABBC 序列任务
     *
     * @return 返回任务启动信息
     */
    @GetMapping("/reentrant-lock")
    public String printABCWithReentrantLock() {
        reentrantLockPrintABCService.printABCSequence();
        return "AAABBC 打印任务 (ReentrantLock) 已启动";
    }

    /**
     * 使用 BlockingQueue 打印 AAABBC 序列任务
     *
     * @return 返回任务启动信息
     */
    @GetMapping("/blocking-queue")
    public String printABCWithBlockingQueue() {
        blockingQueuePrintABCService.printABCSequence();
        return "AAABBC 打印任务 (BlockingQueue) 已启动";
    }

    /**
     * 使用 Semaphore 打印 AAABBC 序列任务
     *
     * @return 返回任务启动信息
     */
    @GetMapping("/semaphore")
    public String printABCWithSemaphore() {
        semaphorePrintABCService.printABCSequence();
        return "AAABBC 打印任务 (Semaphore) 已启动";
    }

    /**
     * 使用 SpinLock 打印 AAABBC 序列任务
     *
     * @return 返回任务启动信息
     */
    @GetMapping("/spin-lock")
    public String printABCWithSpinLock() {
        spinLockPrintABCService.printABCSequence();
        return "AAABBC 打印任务 (SpinLock) 已启动";
    }

    /**
     * 使用 LockSupport 打印 AAABBC 序列任务
     *
     * @return 返回任务启动信息
     */
    @GetMapping("/lock-support")
    public String printABCWithLockSupport() {
        lockSupportPrintABCService.printABCSequence();
        return "AAABBC 打印任务 (LockSupport) 已启动";
    }

    /**
     * 使用 WaitNotify 打印 AAABBC 序列任务
     *
     * @return 返回任务启动信息
     */
    @GetMapping("/wait-notify")
    public String printABCWithWaitNotify() {
        waitNotifyPrintABCService.printABCSequence();
        return "AAABBC 打印任务 (WaitNotify) 已启动";
    }
}
